<template>
  <div class="box">
    <el-container>
      <!-- 头部区域 -->
      <el-header>
        <div class="logo">
          <span>后台管理系统</span>
        </div>
        <div>
          <el-button type="info" @click="logout">退出</el-button>
        </div>
      </el-header>
      <el-container>
        <!-- 左侧区域 -->
        <el-aside class="open" id="aside">
          <p class="cMenu" @click="changeMenu">|||</p>
          <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            background-color="#333744"
            text-color="#fff"
            active-text-color="#ffd04b"
            :collapse="isCollapse"
            router
          >
            <el-menu-item index="/admin/index">
              <i class="el-icon-s-home"></i>
              <span slot="title">首页</span>
            </el-menu-item>

            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-user-solid"></i>
                <span>用户管理</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="/admin/user">
                  <i class="el-icon-user"></i>
                  <span slot="title">用户列表</span>
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>

            <el-submenu index="2">
              <template slot="title">
                <i class="el-icon-star-on"></i>
                <span>权限管理</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="/admin/authority">
                  <i class="el-icon-star-off"></i>
                  <span slot="title">权限列表</span>
                </el-menu-item>
              </el-menu-item-group>
              <el-menu-item-group>
                <el-menu-item index="/admin/authority/role">
                  <i class="el-icon-star-off"></i>
                  <span slot="title">角色列表</span>
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>

            <el-submenu index="3">
              <template slot="title">
                <i class="el-icon-s-goods"></i>
                <span>商品管理</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="/admin/goods">
                  <i class="el-icon-goods"></i>
                  <span slot="title">商品列表</span>
                </el-menu-item>
              </el-menu-item-group>
              <el-menu-item-group>
                <el-menu-item index="/admin/goods/wares">
                  <i class="el-icon-goods"></i>
                  <span slot="title">商品列表1</span>
                </el-menu-item>
              </el-menu-item-group>
              
              <el-menu-item-group>
                <el-menu-item index="/admin/goods/tab">
                  <i class="el-icon-goods"></i>
                  <span slot="title">tab选项卡</span>
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>

            <el-submenu index="5">
              <template slot="title">
                <i class="el-icon-s-order"></i>
                <span>订单管理</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="/admin/olders/older">
                  <i class="el-icon-s-data"></i>
                  <span slot="title">订单列表</span>
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>

            <el-submenu index="6">
              <template slot="title">
                <i class="el-icon-s-data"></i>
                <span>数据统计</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="/admin/statistics">
                  <i class="el-icon-s-data"></i>
                  <span slot="title">数据列表</span>
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <!-- 中间区域 -->
        <el-main>
          <!-- 面包屑 -->
          <div class="box">
            <router-view></router-view>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isCollapse: false,
    };
  },
  created() {},
  mounted() {},
  methods: {
    // 退出登录操作
    logout() {
      this.$confirm("您确定要退出吗？", "提示", {
        confirmButtonText: "确定",
        canceytutttonText: "取消",
        type: "warning",
      })
        .then(() => {
          // 确定要退出登录，删除本地存储
          sessionStorage.removeItem("03B_user");
          // 跳转到登录页面
          this.$router.push("/admin/login");
        })
        .catch(() => {
          this.$message("你已经取消退出登录");
        });
    },
    // 左侧菜单的折叠效果
    changeMenu() {
      this.isCollapse = !this.isCollapse;
      let aside = document.querySelector("#aside");
      if (this.isCollapse == false) {
        aside.className = "el-aside open";
      } else {
        aside.className = "el-aside close";
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.el-container {
  width: 100%;
  .el-header {
    width: 100%;
    background: #373d41;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .logo {
      color: #f8f8f8;
      font-size: 20px;
      font-weight: bold;
    }
  }
  .el-aside {
    background: #333744;
    min-height: 661px;
    color: #fff;
    transition: width 1s ease;
    .cMenu {
      line-height: 30px;
      color: #fff;
      text-align: center;
      border-bottom: 1px solid #f0f0f0;
    }
    .el-menu {
      border-right: none;
    }
  }
  .open {
    width: 200px !important;
  }
  .close {
    width: 64px !important;
  }
  .el-main {
    background: #f0f0f0;
    .box {
      background: #fff;
      padding: 10px;
      box-sizing: border-box;
      margin-top: 10px;
      border-radius: 5px;
    }
  }
}
</style>
